class Solution(object):
    def minTimeToType(self, word):
        n = len(word)
        v = abs(ord(word[0]) - ord('a'))
        ans = min(v, 26 - v)
        for i in range(1, n):
            v = abs(ord(word[i]) - ord(word[i - 1]))
            ans += min(v, 26 - v)
        return ans + n
